<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>小飞象-登录</title>
    <link rel="stylesheet" href="//at.alicdn.com/t/font_848034_62n56i5y1xn.css">
    <link rel="stylesheet" href="css/common/reset.css">
    <link rel="stylesheet" href="layui/css/layui.css">
    <link rel="stylesheet" href="css/reset-layui.css">
    <link rel="stylesheet" href="css/login.css">
</head>

<body>
    <div class="loginView">
        <div class="nav">
            <a href="" class="logo"></a>
            <div class="header-bar-menu">
                <a href="login.html">登录</a> | <a href="register.html">注册</a>
            </div>
        </div>
        <div class="loginPanel">
            <h2>用户登录</h2>
            <form action="" class="layui-form formLogin">
                <div>
                    <i class="iconfont icon-yonghuming"></i>
                    <input type="text" placeholder="用户名" lay-verify="uname" id="uname">
                </div>
                <div>
                    <i class="iconfont icon-mima"></i>
                    <input type="password" placeholder="密码" lay-verify="pwd" id="pwd">
                </div>
                <input type="submit" value="登录" class="btn" lay-submit="" lay-filter="login">
            </form>
            <div class="linkOtherBox">
                <a href="register.html" class="linkRegister"><i class="iconfont icon-jiantou-you"></i>注册会员</a>
                <!-- <a href="" class="linkForgotPwd">忘记密码</a> -->
            </div>
        </div>
    </div>
    <script src="js/jquery.min.js"></script>
    <script src="js/jquery.cookie.js"></script>
    <script src="layui/layui.js"></script>
    <script>
        layui.use(['form', 'jquery', 'layer'], function () {
            var form = layui.form;
            var $ = layui.jquery;
            var layer = layui.layer;
            //自定义验证规则
            form.verify({
                uname: function (value, item) {
                    if (!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)) {
                        return '用户名不能有特殊字符';
                    }
                    if (/(^\_)|(\__)|(\_+$)/.test(value)) {
                        return '用户名首尾不能出现下划线\'_\'';
                    }
                    if (/^\d+\d+\d$/.test(value)) {
                        return '用户名不能全为数字';
                    }
                }
                , pwd: [
                    /^[\S]{6,12}$/
                    , '密码必须6到12位，且不能出现空格'
                ]
            });
            //添加表单监听事件,提交注册信息
            form.on('submit(login)', function () {
                var user = $('#uname').val();
                var pwd = $('#pwd').val();
                var JdateJson = {
                    "loginId": user,
                    "userPassword": pwd
                }
                $.ajax({
                    url: "http://www.xiaofeixiangf.com:8888/v1/client/merchants/enter",
                    type: 'POST',
                    dataType: 'json',
                    contentType: "application/json;charset=utf-8",
                    data: JSON.stringify(JdateJson),
                    success: function (data) {
                        var _Success = data.code;
                        if (_Success == 200) {
                            $.cookie('id', data.data.id);
                            layer.msg("登录成功");
                            // return;
                            location.href = "index.html";
                        } else {
                            layer.msg(data.data);
                        }
                    },
                    error: function () {
                        // layer.msg("服务器异常");
                        console.log("服务器异常")
                    }
                })
                //防止页面跳转
                return false;
            });
        });
    </script>
</body>

</html>